﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZX.BLL.Extend;
using ZX.EHR.Library;
using ZX.Common;
using System.Data;
using System.Data.SqlClient;
namespace ZX.BLL
{
    /// <summary>
    /// 职务管理业务处理类型
    /// </summary>
    public class BDutyInfo : BaseBussnies
    {
        /// <summary>
        /// 根据职务类型ID获取职务列表
        /// </summary>
        /// <param name="DutyId">职务类型ID</param>
        /// <returns></returns>
        public IList<V_DatDutyInfo> GetDutyInfoByDutyId(Guid DutyTypeId)
        {
            this.entity = new V_DatDutyInfo();
            return GetEntitysBySqlComm<V_DatDutyInfo>("select * from V_DatDutyInfo where DutyTypeId='" + CSVHelper.FmSQL(DutyTypeId) + "' order by SequenceNo");
        }
        /// <summary>
        /// 根据职务类型名获取职务列表
        /// </summary>
        /// <param name="DutyName">职务类型名</param>
        /// <returns></returns>
        public IList<V_DatDutyInfo> GetDutyInfoByDutyName(string DutyTypeName)
        {
            this.entity = new V_DatDutyInfo();
            return GetEntitysBySqlComm<V_DatDutyInfo>("select * from V_DatDutyInfo where DutyTypeName='" + CSVHelper.FmSQL(DutyTypeName) + "' order by SequenceNo");
        }
        /// <summary>
        /// 根据职务ID获取职务列表
        /// </summary>
        /// <param name="DutyInfoId">职务ID</param>
        /// <returns></returns>
        public IList<V_DatDutyInfo> GetDutyInfoById(Guid DutyInfoId)
        {
            this.entity = new V_DatDutyInfo();
            return GetEntitysBySqlComm<V_DatDutyInfo>("select * from V_DatDutyInfo where ID='" + CSVHelper.FmSQL(DutyInfoId) + "' order by SequenceNo");
        }
        /// <summary>
        /// 根据职务ID获取职务列表
        /// </summary>
        /// <param name="DutyInfoId">职务ID</param>
        /// <returns></returns>
        public DatDutyInfo GetDatDutyInfoById(Guid DutyInfoId)
        {
            this.entity = new DatDutyInfo();
            return GetEntityByCondition("ID ='" + DutyInfoId + "'") as DatDutyInfo;
        }

        /// <summary>
        /// 判断职务名是否存在
        /// </summary>
        /// <returns></returns>
        public bool IsExistByName(string Name,Guid DutyType)
        {
            this.entity = new DatDutyInfo();
            return GetEntityByCondition("Name='" + Name + "' and DutyTypeId='" + DutyType + "'") != null;
        }
        /// <summary>
        /// 修改时判断职务名称是否已存在
        /// </summary>
        /// <param name="Name"></param>
        /// <param name="Id"></param>
        /// <returns></returns>
        public bool IsExistByNameForUpdate(string Name, Guid Id, Guid DutyType)
        {
            this.entity = new DatDutyInfo();
            return GetEntityByCondition("Name='" + Name + "' and ID<>'" + Id + "' and DutyTypeId='" + DutyType + "'") != null;
        }
        /// <summary>
        /// 根据职务ID获取职务对应职级信息
        /// </summary>
        /// <param name="DutyInfoId"></param>
        /// <returns></returns>
        public IList<DatPostDutygrade> GetDatDutyInfoAndDutyGradeByDutyInfoId(Guid DutyInfoId)
        {
            this.entity = new DatPostDutygrade();
            return GetEntitysBySqlComm<DatPostDutygrade>("select * from DatPostDutygrade where PostID='" + CSVHelper.FmSQL(DutyInfoId) + "'");
        }
        /// <summary>
        /// 获取职等
        /// </summary>
        /// <returns></returns>
        public DataTable GetDatDutyLevel()
        {
            DataTable dt = null;
            SqlParameter[] sqlparams = new SqlParameter[]{};

            DataSet ds = this.RunProcedure("sp_GetDatDutyLevel", sqlparams);
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
            }
            return dt;
        }
    }
}
